package com.android.takegism.utils;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class MyDbOpenHelper extends SQLiteOpenHelper {

    public MyDbOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, "my.db", factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE sensor_package(spid INTEGER PRIMARY KEY AUTOINCREMENT,dataType,dataString,time,data)");
        db.execSQL("CREATE TABLE save_manage(id INTEGER PRIMARY KEY ,deng,wen_shi_du,zi_dong_jia_shi,zi_dong_tiao_wen,threshold_distance," +
                "threshold_illumination,threshold_vibration)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        System.out.println("更新版本");
//        db.execSQL("CREATE TABLE sensor_package(spid INTEGER PRIMARY KEY AUTOINCREMENT,dataType,dataString,time,data)");
//        db.execSQL("CREATE TABLE save_manage(id INTEGER PRIMARY KEY ,deng,wen_shi_du,zi_dong_jia_shi,zi_dong_tiao_wen,threshold_distance," +
//                "threshold_illumination,threshold_vibration)");
        ContentValues cv = new ContentValues();
        cv.put("id","0");
        cv.put("threshold_distance",20);
        cv.put("threshold_illumination",50);
        cv.put("threshold_vibration",1);
        cv.put("deng",0);
        cv.put("zi_dong_jia_shi",0);
        cv.put("zi_dong_tiao_wen",0);
        db.insert("save_manage",null,cv);
    }
}
